// import { useEffect, useRef } from 'react';
import { Navigate, useRoutes } from 'react-router-dom';
// import { useMainStore } from '@/store/main';
import { mapRouters } from './createRouter';
import { menus, features } from '@/mock/menu';
import 'nprogress/nprogress.css';
import type { IRouteObject } from './createRouter';

import Main from '@/layout/Main/Main'; // 主区域容器
import Home from '@/layout/Home/Home';
import NotFound from '@/layout/NotFound/NotFound'; // 404页面

export const routes: IRouteObject[] = [
	{
		path: '/',
		element: <Navigate to="/home" />
	},
	{
		name: 'main',
		// path: '/main',
		element: <Main />,
		children: [
			{
				name: 'home',
				path: '/home',
				meta: { title: '首页' },
				element: <Home />
			},
			...mapRouters(menus),
			{
				path: '*',
				element: <NotFound />
			}
		]
	},
	...mapRouters(features),
	{
		path: '*',
		element: <NotFound />
	}
];

export const RouteList = () => {
	// const { userMenus, featuresRoutes, loadLocalStorage } = useMainStore();
	// const isInitRef = useRef(false);

	// console.log('userMenus', userMenus);

	// useEffect(() => {
	// 	loadLocalStorage();
	// }, []);

	// if (userMenus.length && !isInitRef.current) {
	// 	const userAuthRouters = mapRouters(userMenus);
	// 	const features = mapRouters(featuresRoutes);
	// 	addRouter('main', userAuthRouters);
	// 	addRouter(null, features);
	// 	isInitRef.current = true;
	// }

	return useRoutes(routes);
};
